package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Permission;
import cn.wolfcode.rbac.qo.JSONResult;
import cn.wolfcode.rbac.service.IPermissionService;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private ApplicationContext act;
    @Autowired
    private IPermissionService permissionService;
    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mv=new ModelAndView();
        mv.addObject("permissions",permissionService.selectAll());
        mv.setViewName("/permission/list");

        return mv;
    }

    @RequestMapping("/delete")
    public String delete(Long id){
        permissionService.deleteById(id);
        return "redirect:/permission/list";
    }

    @RequestMapping("/reload")
    @ResponseBody
    public JSONResult reload(){
        try {
            permissionService.reload();
        }catch (Exception e){
            return new JSONResult(false,"权限未更新");
        }
        return new JSONResult(true,"成功");

    }
}
